package com.smart.controller.app;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import com.smart.util.DateUtil;
import com.smart.util.Messages;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import com.smart.req.MainRecordsReq;
import com.smart.entity.SysMainRecords;
import io.swagger.annotations.ApiOperation;
import com.smart.controller.BaseController;
import com.smart.service.MainRecordsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020年6月9日 下午2:49:46
 * Copyright (C) 深圳工勘科技
 * @说明: 保养记录controller
 **/
@RestController("appMainRecordsController")
@RequestMapping("/app/mrecords")
@Api(value="app",tags="保养记录管理")
public class MainRecordsController extends BaseController{

	@Resource
	private MainRecordsService mainRecordsService;
	
	@ApiOperation(value="app获取保养项目列表",notes="app获取保养项目列表")
	@GetMapping(value="/pro_list")
	public Messages<Object> proList(){
		List<Object> list = new ArrayList<>();
		Map<String,Object> map1=new HashMap<>();
		map1.put("id",1);
		map1.put("name","发动机机油");
		list.add(map1);
		Map<String,Object> map2=new HashMap<>();
		map2.put("id",2);
		map2.put("name","空气滤芯");
		list.add(map2);
		Map<String,Object> map3=new HashMap<>();
		map3.put("id",3);
		map3.put("name","柴油滤芯");
		list.add(map3);
		return Messages.success(list);
	}
	
	@ApiOperation(value="app新增保养记录",notes="app新增保养记录")
	@PostMapping(value="/add")
	public Messages<String> save(@RequestBody MainRecordsReq records){
		String contents = records.getContent();
		if(contents.trim().length() > 500){
			return Messages.failed("输入的内容太长!");
		}
		try {
			mainRecordsService.save(records);
			return Messages.success(DateUtil.formatCurrentDateToLongStr());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Messages.failed("录入失败!");
	}
	
	/**
	 * @param params
	 * @return 获取历史记录分页
	 **/
	@ApiOperation(value="app获取保养历史记录列表",notes="app获取保养历史记录列表")
	@GetMapping(value="/page")
	public Messages<List<SysMainRecords>> page(String createTime,
			@RequestParam(name="pageNum")Integer pageNum,
			@RequestParam(name="pageSize")Integer pageSize){
		IPage<SysMainRecords> page=
				mainRecordsService.findPage(pageNum,pageSize,createTime);
		return Messages.success(page.getRecords());
	}
	
}